<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>取回一个数据库连接的属性</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="pdo.exec.html">PDO::exec</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="pdo.getavailabledrivers.html">PDO::getAvailableDrivers</a></div>
 <div class="up"><a href="class.pdo.html">PDO</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="pdo.getattribute" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::getAttribute</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PECL pdo &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">PDO::getAttribute</span> &mdash; <span class="dc-title">
   取回一个数据库连接的属性
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdo.getattribute-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>PDO::getAttribute</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$attribute</code></span>
   )</div>


  <p class="para rdfs-comment">
   此函数（方法）返回一个数据库连接的属性值。 取回 PDOStatement 属性，请参阅 
   <span class="function"><a href="pdostatement.getattribute.html" class="function">PDOStatement::getAttribute()</a></span>。
  </p>

  <p class="para">
   注意有些数据库/驱动可能不支持所有的数据库连接属性。
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-pdo.getattribute-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">attribute</code></em></dt>

     <dd>

      <p class="para">
        <em>PDO::ATTR_*</em> 常量中的一个。下列为应用到数据库连接中的常量： 
       <ul class="simplelist"> 
        <li class="member"><em>PDO::ATTR_AUTOCOMMIT</em></li>
        <li class="member"><em>PDO::ATTR_CASE</em></li>
        <li class="member"><em>PDO::ATTR_CLIENT_VERSION</em></li>
        <li class="member"><em>PDO::ATTR_CONNECTION_STATUS</em></li>
        <li class="member"><em>PDO::ATTR_DRIVER_NAME</em></li>
        <li class="member"><em>PDO::ATTR_ERRMODE</em></li>
        <li class="member"><em>PDO::ATTR_ORACLE_NULLS</em></li>
        <li class="member"><em>PDO::ATTR_PERSISTENT</em></li>
        <li class="member"><em>PDO::ATTR_PREFETCH</em></li>
        <li class="member"><em>PDO::ATTR_SERVER_INFO</em></li>
        <li class="member"><em>PDO::ATTR_SERVER_VERSION</em></li>
        <li class="member"><em>PDO::ATTR_TIMEOUT</em></li>
       </ul> 
      </p>
     </dd>

     
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo.getattribute-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功调用则返回请求的 PDO 属性值。不成功则返回 <em>null</em>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdo.getattribute-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-898">
    <p><strong>Example #1 取回数据库连接属性</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'odbc:sample'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$attributes&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"AUTOCOMMIT"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ERRMODE"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CASE"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CLIENT_VERSION"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CONNECTION_STATUS"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"ORACLE_NULLS"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"PERSISTENT"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"PREFETCH"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SERVER_INFO"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SERVER_VERSION"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"TIMEOUT"<br /></span><span style="color: #007700">);<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$attributes&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"PDO::ATTR_</span><span style="color: #0000BB">$val</span><span style="color: #DD0000">:&nbsp;"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">constant</span><span style="color: #007700">(</span><span style="color: #DD0000">"PDO::ATTR_</span><span style="color: #0000BB">$val</span><span style="color: #DD0000">"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdo.getattribute-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="pdo.setattribute.html" class="function" rel="rdfs-seeAlso">PDO::setAttribute()</a> - 设置属性</span></li>
    <li class="member"><span class="function"><a href="pdostatement.getattribute.html" class="function" rel="rdfs-seeAlso">PDOStatement::getAttribute()</a> - 检索一个语句属性</span></li>
    <li class="member"><span class="function"><a href="pdostatement.setattribute.html" class="function" rel="rdfs-seeAlso">PDOStatement::setAttribute()</a> - 设置一个语句属性</span></li>
   </ul>
  </p>
 </div>



</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="pdo.exec.html">PDO::exec</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="pdo.getavailabledrivers.html">PDO::getAvailableDrivers</a></div>
 <div class="up"><a href="class.pdo.html">PDO</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
